package com.hanamaki.demo01;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;

/**
 * selenium 中八大 元素 的 定位 的方式
 */
public class FireFoxDriver03 {

    WebDriver driver;

    @BeforeClass
    public void setup() {
        System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");
        driver = new FirefoxDriver();
    }

    @Test
    public void test() throws InterruptedException, IOException {
        driver.get("file:///D:/SoftWare/apache-tomcat-9.0.56/webapps/testhtml/exam/House.html");
//        //input[@type='file']
        WebElement element = driver.findElement(By.xpath("//input[@type='file']"));
        /* 如果想要 实现 文件上传 只需要 对抓取出的 元素进行 路径的赋值  即可 */
        element.sendKeys("D:\\SoftWare\\apache-tomcat-9.0.56\\webapps\\testhtml\\exam\\ddd.html");


        /* 截图 */
        File screenshotAs = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(screenshotAs, new File("d:\\image.png"));

    }



    @AfterClass
    public void close() {
//        driver.close();
    }


}
